←Select platform

MergeWith(string[],string) Method

Summary

Merges this PDF file with one or more PDF existing files.

Syntax

C#
C++/CLI
Java
Python
public void MergeWith( 
   string[] sourceFileNames, 
   string destinationFileName 
) 
public void mergeWith( 
   java.lang.String[] string,  
   java.lang.String string 
); 
public: 
void MergeWith(  
   array<String^>^ sourceFileNames, 
   String^ destinationFileName 
)  
def MergeWith(self,sourceFileNames,destinationFileName): 

Parameters

sourceFileNames

An array of System.String's that contain the names of the source files to merge with this PDFFile. Must not be null and must contain at least one item and a maximum of 100 items.

destinationFileName

Name of the destination PDF file to be created. If the value of this parameter is null (Nothing in VB) then the filename set in FileName will be updated.

Remarks

This method will merge two or more existing PDF files to form a new file containing all the pages from the pre-existing PDF files. The new file will be constructed as follows:

When using the MergeWith method, it is important to ensure that the initialPath property is set to the same directory as the Pdf.Utilities.dll.

All PDF files must pre-exist on disk and must be valid. The  sourceFileNames parameter must not contain any null items.

To use this method, associate this PDFFile object with a valid PDF file and optional password. You can achieve this by either using the PDFFile(string fileName) or PDFFile(string fileName, string password) constructors or set the filename and optional password directly into the FileName and Password properties. You do not need to call Load before using this method.

This method will use the following properties of this PDFFile object:

If one or more of the files to merge with are encrypted with a password, then use the MergeWith(PDFFile[] sourceFiles, string destinationFileName) version of this method to pass a list of PDFFile objects instead of just the filenames, and thus, associating each input item with an optional password.

If you wish to merge only a portion (not all the pages) of one or more PDF files, you can use the PDFFile.MergeFiles method instead.

Example

This example will merge a group of PDF files to generate a single document that contains all the pages.

C#
Java
using Leadtools.WinForms; 
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Controls; 
using Leadtools.Drawing; 
using Leadtools.ImageProcessing; 
using Leadtools.Pdf; 
using Leadtools.Svg; 
 
 
public void PDFFileMergeWithExample() 
{ 
   string sourceFileName1 = Path.Combine(LEAD_VARS.ImagesDir, @"File1.pdf"); 
   string sourceFileName2 = Path.Combine(LEAD_VARS.ImagesDir, @"File2.pdf"); 
   string sourceFileName3 = Path.Combine(LEAD_VARS.ImagesDir, @"File3.pdf"); 
 
   string destinationFileName = Path.Combine(LEAD_VARS.ImagesDir, @"Merged.pdf"); 
 
   // Merge 1 with (2, 3) and form destination 
   PDFFile pdfFile = new PDFFile(sourceFileName1); 
   pdfFile.MergeWith(new string[] { sourceFileName2, sourceFileName2 }, destinationFileName); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
 
import java.io.ByteArrayInputStream; 
import java.io.File; 
import java.io.FileInputStream; 
import java.io.FileNotFoundException; 
import java.io.FileOutputStream; 
import java.io.FileReader; 
import java.io.IOException; 
import java.io.InputStream; 
import java.nio.file.Files; 
import java.nio.file.Paths; 
import java.nio.file.StandardCopyOption; 
import java.util.ArrayList; 
import java.util.Date; 
import java.util.List; 
import java.util.Scanner; 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
import static org.junit.Assert.*; 
 
import leadtools.*; 
import leadtools.codecs.*; 
import leadtools.pdf.*; 
 
 
public void pdfFileMergeWithExample() { 
 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
   String sourceFileName1 = combine(LEAD_VARS_IMAGES_DIR, "Leadtools.pdf"); 
   String sourceFileName2 = combine(LEAD_VARS_IMAGES_DIR, "Leadtools.pdf"); 
   String sourceFileName3 = combine(LEAD_VARS_IMAGES_DIR, "Leadtools.pdf"); 
   String destinationFileName = combine(LEAD_VARS_IMAGES_DIR, "Merged.pdf"); 
 
   // Merge 1 with (2, 3) and form destination 
   PDFFile pdfFile = new PDFFile(sourceFileName1); 
   pdfFile.mergeWith(new String[] { sourceFileName2, sourceFileName3 }, destinationFileName); 
 
   PDFFile savedPDF = new PDFFile(destinationFileName); 
   savedPDF.load(); 
   assertTrue(savedPDF.getPageCount() == (pdfFile.getPageCount() * 3)); 
} 

Requirements

Target Platforms

See Also

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Pdf Assembly

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.